﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SharpObjects.SearchEngine.HtmlParsing.Html
{
    public class HtmlMetaTag : HtmlTag
    {
        public HtmlMetaTag(HtmlGenericTag tag = null)
            : base(tag)
        {
        }

        public const string TagName = "meta";

        public override string Name
        {
            get
            {
                HtmlAttribute nameAttribute = GetAttribute("name");
                return "meta_" + nameAttribute.Value;
            }
            set
            {
            }
        }

        public override string Text
        {
            get
            {
                HtmlAttribute contentAttribute = this.GetAttribute("content");
                string text = contentAttribute.Value + " " + base.Text;
                return text;
            }
            set
            {
                base.Text = value;
            }
        }

        public override bool IsClosed { get { return true; } set {} }
        public override bool HasText { get { return true; } set { } }

        public static HtmlTag CreateInstance(HtmlGenericTag tag)
        {
            HtmlAttribute nameAttribute = tag.GetAttribute("name");

            if (nameAttribute.Value.ToLower() == "description")
            {
                return new HtmlMetaDescriptionTag(tag);
            }
            else if(nameAttribute.Value.ToLower() == "keywords")
            {
                return new HtmlMetaKeywordsTag(tag);
            }
            else
            {
                return new HtmlMetaTag(tag);
            }
        }
    }
}
